package asava.names;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Tim Richter
 */
public final class NameTable {
    private final Map<String, Name> map;

    public NameTable() {
        this.map = new HashMap<>();
    }

    public Name enter(final char[] value,
                      final int off,
                      final int len) {
        return enter(new String(value, off, len));
    }

    public Name enter(final String value) {
        Name name = map.get(value);

        if (name == null) {
            name = new Name(this, value);
            map.put(value, name);
        }
        return name;
    }
}
